import { defHttp } from '/@/utils/http/axios';
import { LoginParams, LoginResultModel } from './model';
import { ErrorMessageMode } from '/#/axios';

enum Api {
  // 获取图形验证码
  getInputCode = '/account/randomImage',
  // 登录
  login = '/account/login/global',
  // 登出
  logout = '/account/logout',
}

export function getCodeInfo(key) {
  const url = Api.getInputCode + `/${key}`;
  return defHttp.get({ url: url });
}

/**
 * @description: user login api
 */
export function loginApi(params: LoginParams, mode: ErrorMessageMode = 'modal') {
  return defHttp.post<LoginResultModel>(
    {
      url: Api.login,
      params,
    },
    {
      errorMessageMode: mode,
    }
  );
}

export function logoutApi(mode: ErrorMessageMode = 'modal') {
  const url = Api.logout;
  return defHttp.post(
    { url: url },
    {
      errorMessageMode: mode,
    }
  );
}
